﻿using IcicleFramework.Components.Physics;
using Microsoft.Xna.Framework;

namespace IcicleFramework.Actions.Physics
{
    public class PhysicsImpulseAction : GameAction
    {
        public Vector2 Impulse { get; set; }

        public PhysicsImpulseAction()
        {
            Impulse = Vector2.Zero;
        }

        protected PhysicsImpulseAction(PhysicsImpulseAction old)
            : base(old)
        {
            Impulse = old.Impulse;
        }

        public override void Update(GameTime gameTime)
        {
            var physics = Target.GetComponent<IPhysicsComponent>();

            if (physics != null)
            {
                physics.ApplyImpulse(Impulse);
            }

            Finished = true;
        }

        public override IGameAction DeepClone()
        {
            return new PhysicsImpulseAction(this);
        }
    }
}
